package main

type Handler interface {

	Handle(c *Client, model *MessageModel)

	Support(model *MessageModel) bool
}

var Handlers = &CompositeHandler{
	handlers: []Handler{ &EnterRoomHandler{}, &FrameSyncHandler{} },
}

type CompositeHandler struct {
	handlers []Handler
}

func (handler *CompositeHandler) Handle(c *Client, model *MessageModel) {
	for _, e := range handler.handlers {
		if e.Support(model) {
			e.Handle(c, model)
			return
		}
	}
	logger.Printf("未找到的指令 %v", model)
}

func (handler *CompositeHandler) Support(model *MessageModel) bool { return true }